	var setDateFlag = 0;//设定标志
	var myDate = new Date();
	var year = myDate.getFullYear();
	var month = myDate.getMonth();
	var day = myDate.getDate();
	var nowDate2 = year + "年" + (month+1) + "月" + day + "日";
	var arrayShowDates = [];//当前显示数组
	var calendarDate = [];
	var show = 0;
$(function(){
	//默认显示日期
    $("#courseDateShow").html(nowDate2);
    var time=getNowFormatDate(myDate);
    arrayShowDates.push(getPre7days(myDate));
    arrayShowDates.push(getFirstDayOfWeek(myDate));
    arrayShowDates.push(getNext7days(myDate));
    refreshDatePanel(arrayShowDates, time);
    // 初始化日历
    $("#courseDate_input").calendar({
    	dateFormat: 'yyyy-mm-dd',
    	onClose: function () {
            //$("#courseDate_input").calendar("destroy");
        },
	     onChange: function (p, values, displayValues) {
	        	//console.log(values.toString())
	        if (setDateFlag==0) {
	            arrayShowDates = [];
	            arrayShowDates.push(getPre7days(values));
	            arrayShowDates.push(getFirstDayOfWeek(values));
	            arrayShowDates.push(getNext7days(values));
	            refreshDatePanel(arrayShowDates, values);
	            var nowDate2 = values.toString().split("-")[0] + "年" + values.toString().split("-")[1] + "月" + values.toString().split("-")[2] + "日";
	            $("#courseDateShow").html(nowDate2);
	            //refreshDatePanel(values) 
	        }     
	    },
      
        onOpen: function () {
        	if (setDateFlag == 1) {
        		$("#courseDate_input").calendar("setValue", calendarDate);
        		setDateFlag = 0
        		
        	}
        }

    });
    // 点击查看
    $('.toview_container .toview').click(function(){
        var toviewT = $(this).text().trim();
        if (toviewT=='查看') {
            $(this).parent().siblings('.appointment_content').show();
            $(this).text('收起');
            $(this).css({
                'color':'#999999',
                 'backgroundColor':'#fff'
            })
            toviewT = '收起';
        }else if (toviewT=='收起') {
            $(this).parent().siblings('.appointment_content').hide();
            $(this).text('查看');
            $(this).css({
                'color':'#0E9CFA',
                 'backgroundColor':'#ECF7FF'
            })
             toviewT = '查看';
        }
    })
     
   
})
//获取7天日期
function getFirstDayOfWeek(date) {
    var dayArr = [];
    var day = new Date(date);
    //var num = day.getDay() || 7;
    num = day.getDay();
    for (var i = num; i >= 1; i--) {
        var reg = new RegExp("/", "g");
        //dayArr.push(new Date(day - i * 86400000).toLocaleDateString().replace(reg, '-'));  
        dayArr.push(getNowFormatDate(new Date(day - i * 86400000)));
    }
    for (var x = 0; x < 7 - num; x++) {
        var reg = new RegExp("/", "g");
        //dayArr.push(new Date(day.getTime() + x * 86400000).toLocaleDateString().replace(reg, '-')); 
        dayArr.push(getNowFormatDate(new Date(day.getTime() + x * 86400000)));
    }
    //console.log(dayArr) 
    return dayArr;
};

//获取前7天日期
function getPre7days(date) {
    var pre7day = "";
    pre7day = getNowFormatDate(new Date(new Date(date) - 7 * 86400000));
    return getFirstDayOfWeek(pre7day);
    //console.log(getFirstDayOfWeek(pre7day));
}
function getPre14days(date) {
    var pre7day = "";
    pre7day = getNowFormatDate(new Date(new Date(date) - 14 * 86400000));
    return getFirstDayOfWeek(pre7day);
    //console.log(getFirstDayOfWeek(pre7day));
}
//获取后7天日期
function getNext7days(date) {
    var next7day = "";
    next7day = getNowFormatDate(new Date(new Date(date).getTime() + 7 * 86400000));
    //console.log(getFirstDayOfWeek(next7day)); 
    return getFirstDayOfWeek(next7day);

}
function getNext14days(date) {
    var next7day = "";
    next7day = getNowFormatDate(new Date(new Date(date).getTime() + 14 * 86400000));
    //console.log(getFirstDayOfWeek(next7day)); 
    return getFirstDayOfWeek(next7day);

}
//获取当前时间，格式YYYY-MM-DD
function getNowFormatDate(dates) {
    var date = new Date(dates);
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
    //console.log(currentdate)
}

function refreshDatePanel(arrayShowDates, nowDate) {
    var strDate = "";
    var arrCourseDate = [];
    //arrCourseDate = getFirstDayOfWeek(date);
    arrCourseDate = arrayShowDates;
    var strCourseDate = "";
    var strUl = "";
    for (var i = 0; i < arrCourseDate.length; i++) {
        var strLi = "";
        for (var j = 0; j < arrCourseDate[i].length; j++) {
            if (arrCourseDate[i][j] == nowDate) {
                strLi += '<li id="' + arrCourseDate[i][j] + '" onclick="selectDate(this);"><span data-id="' + arrCourseDate[i][j] + '" class="courseDate-active">' + arrCourseDate[i][j].split('-')[2] + '</span></li>';
            } else {
                strLi += '<li id="' + arrCourseDate[i][j] + '" onclick="selectDate(this);"><span data-id="' + arrCourseDate[i][j] + '">' + arrCourseDate[i][j].split('-')[2] + '</span></li>';
            }

        }
        strUl = '<ul class="swiper-slide course-date">' + strLi + '</ul>';
        strDate += strUl;
        strUl = "";
        //console.log(arrCourseDate[i])
        // if (arrCourseDate[i] == date) {
        //     strDate += '<li id="D_' + arrCourseDate[i] + '" onclick="selectDate(this)"><span class="courseDate-active">' + arrCourseDate[i].split("-")[2] + '</span></li>';
        // } else {
        //     strDate += '<li id="D_' + arrCourseDate[i] + '" onclick="selectDate(this)"><span>' + arrCourseDate[i].split("-")[2] + '</span></li>';
        // }
    }
    $("#course_date").empty();
    $("#course_date").append(strDate);
    strDate = "";
    var swiperIndex = 1;
    var count = 0;
    var swiper = new Swiper('.swiper-container', {
        slidesPerView: 1,
        spaceBetween: 0,
        initialSlide: 1,
        observer: true,//修改swiper自己或子元素时，自动初始化swiper 
        observeParents: false,//修改swiper的父元素时，自动初始化swiper
        // pagination: {
        //     el: '.swiper-pagination',
        //     clickable: true
        // },
        //     onTouchMove: function(e){
        //         var dist=e.touches.currentY-e.touches.startY;
        //         console.log(dist);
        //         if(dist<0){
        //           //向上
        //         }else if(dist>0){
        //            //向下
        //         }

        //  },
        on: {
            slideChange: function (swiper) {
            	
                count++;
                //console.log(count);
                if (count % 2 === 0) {
                    if (this.activeIndex > swiperIndex) {//往后滑
                    	$('.weui-picker-calendar').hide();
                        //console.log($(".swiper-slide-active").children(":first"));
                        //var newFirstDay = $(".swiper-slide-active").children(":first")[0].id;                          
                        var newFirstDay = $(".swiper-slide-active").find(".courseDate-active").attr("data-id");
                        //console.log(newFirstDay);
                        var actived = getNowFormatDate(new Date(new Date(newFirstDay).getTime() + 7 * 86400000));
                        arrayShowDates = [];
                        arrayShowDates.push(getFirstDayOfWeek(newFirstDay));
                        arrayShowDates.push(getNext7days(newFirstDay));
                        arrayShowDates.push(getNext14days(newFirstDay));
                        // $("#course_date").empty();
                        refreshDatePanels(arrayShowDates, actived);
                      
                        calendarDate = [];
                        calendarDate.push(actived);
                        setDateFlag = 1;
                     
                        $("#courseDate_input").val(actived);
                        var nowDate2 = actived.split("-")[0] + "年" + actived.split("-")[1] + "月" + actived.split("-")[2] + "日";
                        $("#courseDateShow").html(nowDate2);
                    } else if (this.activeIndex < swiperIndex) {//往前滑
                    	$('.weui-picker-calendar').hide();
                        //var newFirstDay = $(".swiper-slide-active").children(":first")[0].id;
                        var newFirstDay = $(".swiper-slide-active").find(".courseDate-active").attr("data-id");
                        var actived = getNowFormatDate(new Date(new Date(newFirstDay) - 7 * 86400000));
                        arrayShowDates = [];
                        arrayShowDates.push(getPre14days(newFirstDay));
                        arrayShowDates.push(getPre7days(newFirstDay));
                        arrayShowDates.push(getFirstDayOfWeek(newFirstDay));
                        refreshDatePanels(arrayShowDates, actived);
                        calendarDate = [];
                        calendarDate.push(actived);
                        setDateFlag = 1;
                       
                        $("#courseDate_input").val(actived); 
                        var nowDate2 = actived.split("-")[0] + "年" + actived.split("-")[1] + "月" + actived.split("-")[2] + "日";
                        $("#courseDateShow").html(nowDate2);
                    }
                    this.slideTo(swiperIndex,500);
                }
                swiperIndex = this.activeIndex;
            },

        }
    });
}


function refreshDatePanels(arry, nowDate) {
    //console.log(nowDate);
    var strDate = "";
    var strUl = "";
    for (var i = 0; i < arry.length; i++) {
        var strLi = "";
        for (var j = 0; j < arry[i].length; j++) {
            if (arry[i][j] == nowDate) {
                strLi += '<li id="' + arry[i][j] + '" onclick="selectDate(this);"><span data-id="' + arry[i][j] + '" class="courseDate-active">' + arry[i][j].split('-')[2] + '</span></li>';
            } else {
                strLi += '<li id="' + arry[i][j] + '" onclick="selectDate(this);"><span data-id="' + arry[i][j] + '">' + arry[i][j].split('-')[2] + '</span></li>';
            }
            //strLi += '<li id="' + arry[i][j] + '">' + arry[i][j].split('-')[2] + '</li>';
        }
        strUl = '<ul class="swiper-slide course-date">' + strLi + '</ul>';
        strDate += strUl;
        strUl = "";
    }
    $("#course_date").html(strDate);
    // console.log(strDate);
}

//更新panel
function refreshDatePanel_(date) {
    var dateValue = $("#courseDate_input").val();
    var strDate = "";
    var arrCourseDate = [];
    arrCourseDate = getFirstDayOfWeek(date);
    var strCourseDate = "";
    for (var i = 0; i < arrCourseDate.length; i++) {
        //console.log(arrCourseDate[i])
        if (arrCourseDate[i] == date) {
            strDate += '<li id="D_' + arrCourseDate[i] + '" onclick="selectDate(this)"><span class="courseDate-active">' + arrCourseDate[i].split("-")[2] + '</span></li>';
        } else {
            strDate += '<li id="D_' + arrCourseDate[i] + '" onclick="selectDate(this)"><span>' + arrCourseDate[i].split("-")[2] + '</span></li>';
        }

    }
    $("#course_date").html(strDate);
}
// 选择日期
function selectDate(p) {
    var newDate = p.id;
    $("#course_date li span").removeClass("courseDate-active");
    $("#" + p.id).children().addClass("courseDate-active");
    selectedDate = newDate;
    calendarDate = [];
    calendarDate.push(newDate);
    setDateFlag = 1;
    // $("#courseDate_input").val(newDate); 
    var nowDate2 = newDate.split("-")[0] + "年" + newDate.split("-")[1] + "月" + newDate.split("-")[2] + "日";
    $("#courseDateShow").html(nowDate2);
}